﻿using B.S.BasicData.ErrorCode;
using B.S.BasicData.Read.Apilication.Common.login;
using B.S.BasicData.Read.DTOS;
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace B.S.BasicData.Write.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class LoginController : ControllerBase
    {

        private readonly IMediator mediator;
        private readonly ILogger<LoginController> logger;

        public LoginController(IMediator mediator, ILogger<LoginController> logger)
        {
            this.mediator = mediator;
            this.logger = logger;
        }
        /// <summary>
        /// 用户登录
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public Task<ApiResult<UserDTO>> GetloginHandle(GetloginCommon request)
        {

            try
            {
                logger.LogInformation("用户登录成功");
                return mediator.Send(request);
            }
            catch (Exception ex)
            {
                logger.LogError("用户登录异常" + ex.Message);
                throw;
            }

        }
    }
}
